using Network.Tcp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Sockets;
using System.Text;
using System.Threading.Tasks;

namespace Network.TcpSelect;

public class TcpSelectClient(string name = "TcpSelectClient") : TcpClientBase(name), ITcpSelect
{
    protected override void HandleTcpEvent()
    {
        (this as ITcpSelect).PrepareFds();
        if (RecvSockets == null || RecvSockets.Count == 0)
            return;
        Socket.Select(RecvSockets, null, null, TimeOutMicroSecond);
        foreach (Socket? socket in RecvSockets)
        {
            if (socket != null)
            {
                DoRecv(socket);
            }
        }
    }



    public List<Socket?>? RecvSockets = new List<Socket?>();
    List<Socket?>? ITcpSelect.RecvSockets { get => RecvSockets; set => RecvSockets = value; }
    object ITcpSelect.ConnectDataMutex => ConnectDataMutex;
    List<ConnectData> ITcpSelect.ConnectDatas => ConnectDatas;
}